﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Common
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.Common.Common;
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    var contranctInfoList = Model.InsuranceWarrantyRecordContractInfo;
}
<h4>合同凭证</h4>
<form id="contractInfoForm" enctype="multipart/form-data" method="post">
    <span class="showFileName"></span>
    <a href="javascript:;" class="file margin-l-10">
        <input type="file" id="UploadFile" name="UploadFile" accept="image/*" multiple="multiple" />选择图片
    </a>
    <input type="button" class="btn btn-primary Edit-R margin-l-10" id="uploadContractInfoBtn" value="上传" />
</form>
<table class="table table-responsive table-bordered table-hover" id="Data">
    <tr>
        <th>大小</th>
        <th>上传人</th>
        <th>上传时间</th>
        <th>点击查看</th>
        <th>操作</th>
    </tr>
    @foreach (var item in contranctInfoList)
    {
        <tr>
            <td>
                @(FileHelper.FormatFileSize(item.FileSize))
            </td>
            <td>
                @item.CreatedBy
            </td>
            <td>
                @item.CreatedTime
            </td>
            <td>
                <a class='Edit-R' href='javascript:void(0);' onclick="showImageLayer(this, 'MultiImageLook.html')" imgurl="@(item.PicPath)">
                    查看图片
                </a>
            </td>
            <td>
                <a onclick="deleteContractInfoImage(@item.ID)">删除</a>
            </td>
        </tr>
    }
</table>
<script src="~/Scripts/uploadAdapter/jquery.loadscript.js"></script>
<script src="~/Scripts/uploadAdapter/jquery.uploadAdapter.js"></script>
<script>
    $(function () {
        //上传合同
        $("#uploadContractInfoBtn").click(function () {
            var uploadFileName = $(".showFileName").text();
            if (!uploadFileName || uploadFileName == "") {
                layer.alert("请选择要上传的图片！");
                return false;
            }
            var form = document.getElementById('contractInfoForm');
            var formData = new FormData(form);
            var index= layer.load();//弹出遮罩层
            $.ajax({
                url: "/WorkOrderCommonInfo/SaveInsuranceWarrantyRecordContractInfo?InsuranceWarrantyRecordID=" +@Model.ID,
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function(data) {
                    if (data.success) {
                        $(".showFileName").text("");
                        layer.close(index);//关闭遮罩层
                        layer.alert(data.message, 
                            { time: 2000,
                            yes:function() {                              
                                $("#Data").load("/WorkOrderCommonInfo/InsuranceWarrantyRecordContractInfo?insuranceWarrantyRecordID=" +@Model.ID +" #Data");
                            },
                            end:function() {
                                $("#Data").load("/WorkOrderCommonInfo/InsuranceWarrantyRecordContractInfo?insuranceWarrantyRecordID=" +@Model.ID + " #Data");
                            }
                        });
                    } else {
                        layer.alert(data.message);
                    }
                }
            });
            return true;
        });
    });

    //删除图片
    function deleteContractInfoImage(id) {
        layer.confirm('确定要删除吗？', {
            time: 2000,
            yes: function(result) {
                if (result) {
                    $.ajax({
                        url: "/WorkOrderCommonInfo/DeleteInsuranceWarrantyRecordContractInfo?ID=" + id,
                        type: "post",
                        processData: false,
                        contentType: false,
                        success: function(data) {
                            if (data.success) {
                                layer.alert(data.message);
                                @*layer.alert(data.message, function() {
                                    layer.close();
                                    $("#Data").load("/WorkOrderCommonInfo/InsuranceWarrantyRecordContractInfo?insuranceWarrantyRecordID=" +@Model.ID +" #Data");
                                });*@
                                $("#Data").load("/WorkOrderCommonInfo/InsuranceWarrantyRecordContractInfo?insuranceWarrantyRecordID=" +@Model.ID +" #Data");
                    } else {
                        layer.alert(data.message);
                    }
                }
            });
        }},icon:3});
    }
</script>
